using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;    

public class btCylinderCollider : btRigidBody {
	
	public float radius = 4.06f;
	public float height = 0.67f;
	public float mass = 1.0f;
	public float restitution = 0;
	public float linearDamping = 0;
	public float angularDamping = 0;
	public float friction = 0;
	public float linearThreshold = 0;
	public float angularThreshold = 0;

	private uint id, colliderId;
	private float pX, pY, pZ;
	private float rX, rY, rZ, rW;
		
	private float d1, d2, d3;
	
	[DllImport ("__Internal")] private static extern uint createCylinderShape(float radius, float height, out uint colliderId);
	//[DllImport ("__Internal")] private static extern void createRigidBody(float X, float Y, float Z, float rX, float rY, float rZ, float rW, float mass, out uint id, uint colliderId);
	//[DllImport ("__Internal")] private static extern void getPosition(out float X, out float Y, out float Z, uint id);
	//[DllImport ("__Internal")] private static extern void getRotation(out float rX, out float rY, out float rZ, out float rW, uint id);
	
	void Start () 
	{
		createCylinderShape(radius, height, out colliderId);
		createRigidBody(transform.position.x, transform.position.y, transform.position.z, 
						transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w, 
						mass, 
						restitution,
						linearDamping, angularDamping, 
						friction, 
						linearThreshold, angularThreshold,out 
						id, colliderId);
		
		//traceLog(out d1, out d2, out d3);
		//Debug.Log(d1 + " " + d2 + " " + d3);
	}	
	
	void Update () 
	{
		/*pX = transform.position.x;
		pY = transform.position.y;
		pZ = transform.position.z;
		rX = transform.rotation.x;
		rY = transform.rotation.y;
		rZ = transform.rotation.z;
		rW = transform.rotation.w;*/
		
		//Debug.Log("cylinder before: " + pX + ", " + pY + ", " + pZ + ", " + rX + ", " + rY + ", " + rZ + ", " + rW );
		getOrigin(out pX, out pY, out pZ, id);
		transform.position = new Vector3(pX, pY ,pZ);
		getRotation(out rX, out rY, out rZ, out rW, id);
		transform.rotation = new Quaternion(rX,rY,rZ,rW);
		//Debug.Log("cylinder after: " + pX + ", " + pY + ", " + pZ+ ", " + rX + ", " + rY + ", " + rZ + ", " + rW );
	}
}